package com.jozen.smart_toilet_system.ui.common_tag_view;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.jozen.modelbase.netwoek.bean.SmartToiletInterfaceConfModel;
import com.jozen.modelbase.netwoek.util.DensityUtil;
import com.jozen.modelbase.netwoek.util.GlideUtil;
import com.jozen.smart_toilet_system.R;

public class CommonTagView extends RelativeLayout {
    private Context context;
    private static int viewWidth = 0, viewHeight = 0;
    private ImageView iv_tag_img;

    public CommonTagView(Context context) {
        super(context);
        this.context = context;
        initViews();
    }

    private void initViews() {
        LayoutInflater.from(context).inflate(R.layout.zt_common_tag_layout, this, true);
        iv_tag_img = (ImageView) findViewById(R.id.iv_tag_img);
    }

    /**
     * 动态数据
     *
     * @param model
     */
    public void setData(SmartToiletInterfaceConfModel.ListDto model,String signature) {
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) iv_tag_img.getLayoutParams();
        params.width = DensityUtil.px2dip(context, model.getWidth());
        params.height = DensityUtil.px2dip(context, model.getHeight());
        iv_tag_img.setLayoutParams(params);
        if (!TextUtils.isEmpty(model.getImagePath())) {
            GlideUtil.loadImageWithCache(model.getImagePath(), R.drawable.ic_overtime, iv_tag_img,signature);
        } else {
            iv_tag_img.setImageResource(0);
        }
    }
}
